#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;

int n, fa[N], dep[N], a[N];
ll f[N][2];
vec G[N], pot[N];

void dfs(int x, int p) {
	fa[x] = p; dep[x] = dep[p] + 1; pot[dep[x]].pb(x);
	for(auto y : G[x]) if(y ^ p) dfs(y, x);
}

void solve() {
	n = in; 
	rep(i, 2, n) { int f = in; G[f].pb(i); G[i].pb(f); } rep(i, 2, n) a[i] = in;
	dfs(1, 0);
	ll ans = 0;
	f[1][0] = f[1][1] = 0;
	rep(d, 2, n) if(pot[d].size()) {
		sort(pot[d].begin(), pot[d].end(), [](int x, int y) { return a[x] < a[y];} );
		int mx = -1, mn = 1e9;
		for(auto x : pot[d]) mx = max(mx, a[x]), mn = min(mn, a[x]);
		for(auto x : pot[d]) {
			f[x][0] = f[fa[x]][0] + max(abs(mx - a[x]), abs(mn - a[x]));
		}
		ll res = -1e18;
		for(auto x : pot[d]) {
			f[x][1] = res + a[x]; res = max(res, f[fa[x]][0] - a[x]);
		}
		res = -1e18; reverse(pot[d].begin(), pot[d].end());
		for(auto x : pot[d]) {
			f[x][1] = max(f[x][1], res - a[x]); res = max(res, f[fa[x]][0] + a[x]);
		}
		for(auto x : pot[d]) f[x][0] = max(f[x][0], f[x][1]), ans = max(ans, f[x][0]);
	} else break;
	printf("%lld\n", ans);
	rep(i, 1, n) G[i].clear(), pot[i].clear();
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    int T = in; while(T--) solve(); return 0;
}
